package main

import (
	"runtime"
	"sjy/customcmd/src/ability"
	"sjy/customcmd/src/event"

	"github.com/astaxie/beego/logs"
)

func main() {
	container(func() {
		// 读取全局配置 局部配置
		event.InitConfig()
		// 解析命令
		cmdObj := event.Parsing()
		// 执行命令
		ability.Execute(&ability.FuncEntity{
			Paramenter: cmdObj,
		})
	})
}

func container(f func()) {
	func() {
		defer func() {
			if err := recover(); err != nil {
				// 所有error如果不单独处理，都认为是我预期外的error
				buf := make([]byte, 4096)
				n := runtime.Stack(buf, false)
				stackInfo := string(buf[:n])
				logs.Error("Cmd Tools Error panic:", err, stackInfo)
			}
		}()

		f()

	}()
}
